package ar.com.spsolutions.splibrary.utils;

import java.util.Random;

public class PasswordUtil {

    private static final Random RANDOM = new Random();

    private static final String NUMEROS = "0123456789";

    private static final String MAYUSCULAS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

    private static final String MINUSCULAS = "abcdefghijklmnopqrstuvwxyz";

    private PasswordUtil() {
        throw new UnsupportedOperationException();
    }

    //
    public static String getPinNumber() {
        return getPassword(NUMEROS, 4);
    }

    public static String getPassword() {
        return getPassword(8);
    }

    public static String getPassword(final int length) {
        return getPassword(NUMEROS + MAYUSCULAS + MINUSCULAS, length);
    }

    public static String getPassword(final String key, final int length) {
        StringBuffer pswd = new StringBuffer();
        for (int i = 0; i < length; i++) {
            int keyLength = key.length();
            int seed = RANDOM.nextInt(keyLength);
            pswd.append(key.charAt(seed));
        }

        return pswd.toString();
    }

}